﻿using Mak_model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;


namespace Mark_dal
{
    public class buygoods_dal
    {
        DBHelper hp = new DBHelper();
        public List<GoodsInfo> QueryListByCode(string code)
        {
            List<GoodsInfo> lie = new List<GoodsInfo>();
            string sql = "select * from GoodsInfo where goodscode like '%" + code + "%'";
            SqlDataReader a=hp.GetAll(sql);
           
            while (a.Read())
            {
                GoodsInfo g = new GoodsInfo();
                if (a["Company"] != DBNull.Value) 
                {
                    g.Company = Convert.ToInt32(a["Company"]);
                }

                if (a["SalePrice"] != DBNull.Value)
                {
                    g.SalePrice = Convert.ToDouble(a["SalePrice"]);
                }

                if (a["GoodsCode"] != DBNull.Value)
                {
                    g.GoodsCode = a["GoodsCode"].ToString();
                }

                if (a["GoodsName"] != DBNull.Value)
                {
                    g.GoodsName = a["GoodsName"].ToString();
                }

                if (a["GoodsState"] != DBNull.Value)
                {
                    g.GoodsState = Convert.ToInt32(a["GoodsState"]);
                }
                if (a["OriginPrice"] != DBNull.Value)
                {
                    g.OriginPrice = Convert.ToDouble(a["OriginPrice"]);
                }

                if (a["Stock"] != DBNull.Value)
                {
                    g.Stock = Convert.ToInt32(a["Stock"]);
                }
                if (a["Supplier"] != DBNull.Value)
                {
                    g.Supplier = Convert.ToInt32(a["Supplier"]);
                }
                if (a["Unit"] != DBNull.Value)
                {
                    g.Unit = a["Unit"].ToString();
                }

                lie.Add(g);
             
            }
            a.Close();
            hp.Close();
            return (lie);
            
            
        }
     
    }
   
}
